package code.twopoint;

public class 两数之和输入有序数组java {
    public static void main(String[] args) {

    }

    public static int[] twoSum(int[] numbers, int target) {
        int[] ans = new int[2];
        int left = 0;
        int right = numbers.length - 1;
        while (left < right) {
            int sum = numbers[left] + numbers[right];
            if (sum == target){
                break;
            }else if (sum<target){
                left++;
            }else {
                right--;
            }
        }
        ans[0] = left+1;
        ans[1] = right+1;
        return ans;
    }
}
